﻿package org.flixel.system.input
{

    public class Input extends Object
    {
        var _lookup:Object;
        var _map:Array;
        const _total:uint = 256;

        public function Input()
        {
            this._lookup = new Object();
            this._map = new Array(this._total);
            return;
        }// end function

        public function update() : void
        {
            var _loc_2:Object = null;
            var _loc_1:uint = 0;
            while (_loc_1 < this._total)
            {
                
                _loc_2 = this._map[_loc_1++];
                if (_loc_2 != null)
                {
                    if (_loc_2.last == -1 && _loc_2.current == -1)
                    {
                        _loc_2.current = 0;
                    }
                    else if (_loc_2.last == 2 && _loc_2.current == 2)
                    {
                        _loc_2.current = 1;
                    }
                    _loc_2.last = _loc_2.current;
                }
            }
            return;
        }// end function

        public function reset() : void
        {
            var _loc_2:Object = null;
            var _loc_1:uint = 0;
            while (_loc_1 < this._total)
            {
                
                _loc_2 = this._map[_loc_1++];
                if (_loc_2 != null)
                {
                    this[_loc_2.name] = false;
                    _loc_2.current = 0;
                    _loc_2.last = 0;
                }
            }
            return;
        }// end function

        public function pressed(param1:String) : Boolean
        {
            return this[param1];
        }// end function

        public function justPressed(param1:String) : Boolean
        {
            return this._map[this._lookup[param1]].current == 2;
        }// end function

        public function justReleased(param1:String) : Boolean
        {
            return this._map[this._lookup[param1]].current == -1;
        }// end function

        public function record() : Array
        {
            var _loc_3:Object = null;
            var _loc_1:Array = null;
            var _loc_2:uint = 0;
            while (_loc_2 < this._total)
            {
                
                _loc_3 = this._map[_loc_2++];
                if (!(_loc_3 == null || _loc_3.current == 0))
                {
                    if (_loc_1 == null)
                    {
                        _loc_1 = new Array();
                    }
                    _loc_1.push({code:(_loc_2 - 1), value:_loc_3.current});
                }
            }
            return _loc_1;
        }// end function

        public function playback(param1:Array) : void
        {
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_2:uint = 0;
            var _loc_3:* = param1.length;
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = param1[_loc_2++];
                _loc_5 = this._map[_loc_4.code];
                _loc_5.current = _loc_4.value;
                if (_loc_4.value > 0)
                {
                    this[_loc_5.name] = true;
                }
            }
            return;
        }// end function

        public function getKeyCode(param1:String) : int
        {
            return this._lookup[param1];
        }// end function

        public function any() : Boolean
        {
            var _loc_2:Object = null;
            var _loc_1:uint = 0;
            while (_loc_1 < this._total)
            {
                
                _loc_2 = this._map[_loc_1++];
                if (_loc_2 != null && _loc_2.current > 0)
                {
                    return true;
                }
            }
            return false;
        }// end function

        protected function addKey(param1:String, param2:uint) : void
        {
            this._lookup[param1] = param2;
            this._map[param2] = {name:param1, current:0, last:0};
            return;
        }// end function

        public function destroy() : void
        {
            this._lookup = null;
            this._map = null;
            return;
        }// end function

    }
}
